import com.pig4cloud.pig.admin.PigAdminApplication;
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.common.RemotingHelper;
import org.apache.rocketmq.remoting.exception.RemotingException;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import java.io.UnsupportedEncodingException;

@SpringBootTest(classes = PigAdminApplication.class)
@RunWith(SpringRunner.class)
public class rocketProducer {

	@Test
	public void sendMessage() throws MQClientException, RemotingException, InterruptedException, MQBrokerException, UnsupportedEncodingException {
		String topic = "my-topic";
		String message = "thisismessage";

		String producerGroup = "test-group";
		DefaultMQProducer producer = new DefaultMQProducer(producerGroup);
		String nameServer = "192.168.44.100:9876";
		producer.setNamesrvAddr(nameServer);
		producer.start();

		Message msg = new Message(topic, String.valueOf(0), message.getBytes(RemotingHelper.DEFAULT_CHARSET));
		producer.send(msg);

		producer.shutdown();
	}
}